package billingServer;

import java.io.Serializable;
import java.util.List;

/**
 * Represents the bill for one user.
 * Contains a collection of all AuctionBills of the user.
 * @author Group 95
 */
public class Bill implements Serializable {
    
    private static final String NEW_LINE=System.getProperty("line.separator");

    private static final String LISTHEADER =
            "auction_ID" + "\t"
            + "strike_price" + "\t"
            + "fee_fixed" + "\t"
            + "fee_variable" + "\t"
            + "fee_total";
    
    private final String owner;
    private final List<AuctionBill> auctionBills;
    
    /**
     * Bill for one user.
     * Contains all of the user's ended auctions.
     * @param owner
     * @param auctionBills 
     */
    public Bill(final String owner, final List<AuctionBill> auctionBills) {
        this.owner = owner;
        this.auctionBills = auctionBills;
    }
    
    /**
     * Create table-representation of user's bill.
     * Every row represents one of the user's auctions.
     * @return 
     */
    public String toLine() {
        final StringBuilder strB=new StringBuilder(LISTHEADER);
       
        for(AuctionBill b : auctionBills) {
            strB.append(NEW_LINE).append(b.toLine());
        }
        
        return strB.toString();
    }
}
